package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "护理计划")
@Slf4j
@RequestMapping("/nursing/plan")
public class NursingPlanController {
    @Resource
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询全部护理计划")
    public ResponseResult<List<NursingPlanVo>> queryAllPlan(){
    List<NursingPlanVo> nursingPlanVos = nursingPlanService.queryAllPlan();
    return ResponseResult.success(nursingPlanVos);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult add(
            @ApiParam(value = "护理计划数据传输对象",required = true)
            @RequestBody NursingPlanDto nursingPlanDto){
        log.info("--------------------------nursingPlanDto={}",nursingPlanDto);
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/search")
    @ApiOperation("护理计划条件分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "planName",required = false) String name,
            @RequestParam(value = "状态:0,1-启用") Integer status,
            @RequestParam(value = "页码") Integer pageSize,
            @RequestParam(value = "每页大小") Integer pageNum){
        PageResponse<NursingPlanVo> nursingPlanVo = nursingPlanService.getByPage(name,status,pageNum,pageSize);
        return ResponseResult.success(nursingPlanVo);
    }

    @GetMapping("/{id}")
    @ApiOperation("护理计划根据id查询")
    public ResponseResult queryById(
            @ApiParam(value = "护理计划id",required = true)
            @PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.queryById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理计划")
    public ResponseResult update(
            @ApiParam(value = "要修改的护理信息",required = true)
            @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return ResponseResult.success();
    }

}
